//
//  wjchaxunViewController.m
//  tongxiangOASystem
//
//  Created by michael on 2018/3/30.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "wjchaxunViewController.h"
#import "shouwenlistViewController.h"
#import "fawenlistViewController.h"
#import "shifulistViewController.h"
#import "shiweilistViewController.h"
@interface wjchaxunViewController ()
@property (nonatomic,strong)NSArray* array;
@property (nonatomic,strong)NSArray* array1;
@property (nonatomic,strong)NSArray* imagearray;


@end

@implementation wjchaxunViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"文件查询";
    _array = [NSArray arrayWithObjects:@"市委文件",@"市府文件",@"发文查询",@"收文查询",nil];
        _array1 = [NSArray arrayWithObjects:@"发文查询",@"收文查询",nil];

            self.view.backgroundColor = [UIColor colorWithHexString:@"efeff4"];
                [MBProgressHUD showHUDAddedTo:self.view animated:YES];

            [self loaddata];
    // Do any additional setup after loading the view.
}
- (void)loaddata{

 NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchmain arrays:array method:@"homedotwo" success:^(id JSON) {
          [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

    if (![JSON isKindOfClass:[NSDictionary class]]) {
    [self.view makeToast:@"服务器出错!"];
}else{
if ([[NSString stringWithFormat:@"%@",JSON[@"dotwo"]]isEqualToString:@"0"]) {
    _imagearray = _array1;
[self initview];

}else{
_imagearray = _array;
[self initview];

}
}

    } failure:^(NSError *error) {
              [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

    }];
  


}
- (void)initview{
//_imagearray = _array;
    for (int i = 0; i < _imagearray.count; i ++) {
 UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
 if (i==0) {
          button.frame = CGRectMake(KScreenWidth/2-10-150, 150, 150, 80);
}else if (i==1) {
          button.frame = CGRectMake(KScreenWidth/2+10, 150, 150, 80);
}else if (i==2) {
          button.frame = CGRectMake(KScreenWidth/2-10-150, 150+80+10, 150, 80);
}else{
          button.frame = CGRectMake(KScreenWidth/2+10, 150+80+10, 150, 80);
}
button.tag = 100+i;
       [ button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",_imagearray[i]]] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];


}
}
- (void)buttonClick:(UIButton *)btn{
if ([_imagearray[btn.tag-100]isEqualToString:@"市委文件"]) {
shiweilistViewController *vc = [[shiweilistViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
    
}else if ([_imagearray[btn.tag-100]isEqualToString:@"市府文件"]) {
shifulistViewController *vc = [[shifulistViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
    
}else if ([_imagearray[btn.tag-100]isEqualToString:@"发文查询"]) {
fawenlistViewController *vc = [[fawenlistViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
    
}else{
shouwenlistViewController *vc = [[shouwenlistViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];

}

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
